package com.android.support.lib.universal.adapter;

import java.util.List;

import com.android.support.lib.universal.slidingtab.SlidingTabLayout;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * Fragment的适配器，实现implements SlidingTabLayout.TabItemName，用来添加滑动条的标题。不需要可以去掉
 * 
 * @author 彭治铭
 *
 */
public class TabFragmentPagerAdapter extends FragmentPagerAdapter implements
		SlidingTabLayout.TabItemName {

	private List<Fragment> mFragmentList;
	private List<String> mTabList;

	/**
	 * 
	 * @param fm
	 *            就传getSupportFragmentManager()
	 * @param fragmentList
	 *            Fragment集合
	 * @param tabList
	 *            标题
	 */
	public TabFragmentPagerAdapter(FragmentManager fm,
			List<Fragment> fragmentList, List<String> tabList) {
		super(fm);
		mFragmentList = fragmentList;
		mTabList = tabList;
	}

	@Override
	public Fragment getItem(int position) {
		return mFragmentList.get(position);
	}

	@Override
	public int getCount() {
		return mFragmentList == null ? 0 : mFragmentList.size();
	}

	@Override
	public String getTabName(int position) {
		if(mTabList!=null){
			return mTabList.get(position);
		}
		return "";
	}

}